import 'package:flutter/material.dart';
import 'package:honeypotflutter/modules/preferences/api/preferencesApi.dart';
import 'package:honeypotflutter/publicBussine/bussine_colors.dart';
import 'package:honeypotflutter/publicBussine/bussine_font.dart';
import 'package:honeypotflutter/publicBussine/bussine_image.dart';
import '../model/preferences_listModel.dart';

class PreferencesListItem extends StatelessWidget {
  /// item 数据
  final PreferencesListModel itemModel;

  final Function()? deleteAction;

  const PreferencesListItem({
    super.key,
    required this.itemModel,
    this.deleteAction,
  });

  /*
  *  删除
  * */
  delete() async {
    PreferencesApi.delete(this.itemModel.id ?? 0).then((value) {
      (deleteAction != null) && deleteAction!();
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(borderRadius: BorderRadius.circular(8), color: MGColors.itemColor),
      padding: EdgeInsets.all(20),
      margin: EdgeInsets.only(left: 16, right: 16, top: 12),
      child: Column(
        children: [
          Text(itemModel.phone ?? "",
              style: TextStyle(
                fontSize: MGFont.textFont1,
                color: MGColors.text1Color,
                fontWeight: FontWeight.bold,
              )),
          SizedBox(height: 5),
          Row(
            children: [
              Text(itemModel.remarks ?? "",
                  style: TextStyle(
                    fontSize: MGFont.textFont3,
                    color: MGColors.text3Color,
                  )),
              InkWell(
                  child: Row(
                    children: [
                      Image.asset(
                        MGImage.image("preferences_delete", type: ImagePathType.preferences),
                        width: 18,
                      ),
                      SizedBox(width: 5),
                      Text("删除",
                          style: TextStyle(
                            fontSize: MGFont.textFont3,
                            color: MGColors.text3Color,
                          ))
                    ],
                  ),
                  onTap: delete)
            ],
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
          )
        ],
        crossAxisAlignment: CrossAxisAlignment.start,
      ),
    );
  }
}
